{include file="public/layout.htm" /}
<script type="text/javascript" src="__SKIN__/js/clipboard.min.js"></script>
<body class="">
    <div class="ey-content back-c">
        <div class="order-detail-wrap">
            <div class="status-wrap after-status-wrap color-base-bg">
                <div class="container">
                    <div class="status-name">
                        {eq name="$Service.status" value="1"}申请维权{/eq}
                        {if condition="2 == $Service.status && in_array($Service.service_type, [1, 2])"}申请已同意，待买家退货{/if}
                        {if condition="2 == $Service.status && in_array($Service.service_type, [3])"}申请已同意，请给买家退款{/if}
                        {eq name="$Service.status" value="4"}买家已退货，商家待收货{/eq}
                        {if condition="5 == $Service.status && 1 == $Service.service_type"}商家已收到退货，待重新发货{/if}
                        {if condition="5 == $Service.status && 2 == $Service.service_type"}商家已收到退货，待转账{/if}
                        {in name="$Service.status" value="3, 6, 7, 8"}维权结束{/in}    
                    </div>
                </div>
            </div>

            <div class="block-wrap">
                <div class="goods-item-wrap">
                    <div class="goods-item">
                        <div class="goods-img"><img src="{$Service.product_img}"></div>
                        <div class="info-wrap">
                            <div class="name-wrap">{$Service.product_name}</div>
                            <div class="spec-wrap">{$Service.product_spec}</div>
                            <div class="more-wrap">
                                <div class="goods-class">{$Details.prom_type_goods}</div>
                                <div class="price-wrap">
                                    <div class="price">
                                        {empty name="$Order.points_shop_order"}
                                        <span class="unit">￥</span>
                                        {/empty}
                                        <span class="">{$Details.product_price}</span>
                                    </div>
                                    <div class="num">x{$Service.product_num}</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="block-wrap">
                <div class="title">订单信息</div>
                <div class="order-cell">
                    <div class="tit"><span>订单类型：</span></div>
                    <div class="box">{$Order.prom_type_name}</div>
                </div>
                <div class="order-cell">
                    <div class="tit"><span>订单编号：</span></div>
                    <div class="box">{$Order.order_code}</div>
                    <div class="copy color-base-text order_code" onclick="textCopy('order_code');" data-clipboard-text="{$Order.order_code}">复制</div>
                </div>
                <div class="order-cell">
                    <div class="tit"><span>服务单号：</span></div>
                    <div class="box">{$Service.refund_code}</div>
                    <div class="copy color-base-text refund_code" onclick="textCopy('refund_code');" data-clipboard-text="{$Service.refund_code}">复制</div>
                </div>
                <div class="order-cell">
                    <div class="tit"><span>买家信息：</span></div>
                    <div class="box">{$Users.nickname}</div>
                </div>
                <div class="order-cell">
                    <div class="tit"><span>付款方式：</span></div>
                    <div class="box">{eq name="$Order.order_source" value="30"}积分兑换{else/}{$Order.pay_name_show}{/eq}</div>
                </div>
                <div class="order-cell">
                    <div class="tit"><span>配送方式：</span></div>
                    <div class="box">{if condition="$Order.prom_type == 0"}{eq name="$Order.logistics_type" value="1"}物流配送{else/}到店自提{/eq}{elseif condition="$Order.prom_type == 1"}无需物流{/if}</div>
                </div>
            </div>

            <div class="block-wrap">
                <div class="order-cell">
                    <div class="tit"><span>商品金额：</span></div>
                    <div class="box font-size-base align-right bold pd0">{empty name="$Order.points_shop_order"}￥{/empty}{$Order.order_total_amount}</div>
                </div>
                <div class="order-cell" {if condition="$Order.shipping_fee <= 0"} style="display: none;" {/if}>
                    <div class="tit"><span>运费金额：</span></div>
                    <div class="box font-size-base align-right bold pd0">￥{$Order.shipping_fee}</div>
                </div>
                <div class="order-cell">
                    <div class="box align-right pd0 bold">
                        <span class="">实付金额：</span>
                        {empty name="$Order.points_shop_order"}
                        <span class="fs11 color-base-text">￥</span>
                        {/empty}
                        <span class="font-size-base color-base-text">{$Order.order_amount}</span>
                    </div>
                </div>
            </div>

            {in name="$Service.service_type" value="1, 2"}
                <!-- 退货时显示 -->
                <div class="block-wrap">
                    <div class="title">买家退货信息</div>
                    <div class="order-cell">
                        <div class="tit"><span>快递公司：</span></div>
                        <div class="box align-right pd0">{empty name='$Service.users_delivery.name'}-{else/}{$Service.users_delivery.name}{/empty}</div>
                    </div>
                    <div class="order-cell">
                        <div class="tit"><span>快递单号：</span></div>
                        <div class="box align-right pd0">{empty name='$Service.users_delivery.order'}-{else/}{$Service.users_delivery.order}{/empty}</div>
                    </div>
                    <!-- <div class="order-cell">
                        <div class="tit"><span>快递费用：</span></div>
                        <div class="box align-right pd0">{empty name='$Service.users_delivery.cost'}-{else/}￥{$Service.users_delivery.cost}{/empty}</div>
                    </div>
                    <div class="order-cell">
                        <div class="tit"><span>发货时间：</span></div>
                        <div class="box align-right pd0">{empty name='$Service.users_delivery.time'}-{else/}{$Service.users_delivery.time}{/empty}</div>
                    </div> -->
                </div>
                {eq name="$Service.service_type" value="1"}
                <!-- 商家发货后显示 -->
                <div class="block-wrap">
                    <div class="title">商家重发信息</div>
                    <div class="order-cell">
                        <div class="tit"><span>快递公司：</span></div>
                        <div class="box align-right pd0">{empty name='$Service.admin_delivery.name'}-{else/}{$Service.admin_delivery.name}{/empty}</div>
                    </div>
                    <div class="order-cell">
                        <div class="tit"><span>快递单号：</span></div>
                        <div class="box align-right pd0">{empty name='$Service.admin_delivery.code'}-{else/}{$Service.admin_delivery.code}{/empty}</div>
                    </div>
                    <div class="order-cell">
                        <div class="tit"><span>发货时间：</span></div>
                        <div class="box align-right pd0">{empty name='$Service.admin_delivery.time'}-{else/}{$Service.admin_delivery.time}{/empty}</div>
                    </div>
                </div>
                {/eq}
            {/in}

            <div class="block-wrap">
                <div class="title">售后信息</div>
                <div class="order-cell">
                    <div class="tit"><span>联系人：</span></div>
                    <div class="box align-right pd0">{$Service.consignee}</div>
                </div>
                <div class="order-cell">
                    <div class="tit"><span>联系电话：</span></div>
                    <div class="box align-right pd0">{$Service.mobile}</div>
                </div>
                {eq name="$Service.service_type" value="1"}
                <div class="order-cell">
                    <div class="tit"><span>联系地址：</span></div>
                    <div class="box align-right pd0">{$Service.address}</div>
                </div>
                {/eq}
                <div class="order-cell">
                    <div class="tit"><span>申请时间：</span></div>
                    <div class="box align-right pd0">{$Service.add_time}</div>
                </div>
                <div class="order-cell">
                    <div class="tit"><span>维权类型：</span></div>
                    <div class="box align-right color-base-text pd0">{$Service.TypeName}</div>
                </div>
                <div class="order-cell" {eq name="$Service.service_type" value="1"} style="display: none;" {/eq}>
                    <div class="tit"><span>退款金额：</span></div>
                    <div class="box align-right color-base-text pd0">
                        ￥{if condition="!empty($Order.actualPayPrice)"}{$Order.actualPayPrice}{else/}{$Service.refund_price}{/if}
                    </div>
                </div>
                <div class="order-cell">
                    <div class="tit"><span>维权原因：</span></div>
                    <div class="box align-right pd0">{$Service.refund_reason}</div>
                </div>
                <div class="order-cell">
                    <div class="tit"><span>维权描述：</span></div>
                    <div class="box align-right pd0">{$Service.content}</div>
                </div>
                {eyou:notempty name='$Service.upload_img' /}
                <div class="order-cell">
                    <div class="tit"><span>维权图片：</span></div>
                    <div class="box align-right pd0" style="white-space: unset;">
                        {volist name="$Service.upload_img" id="vo"}
                        <a href="{$vo}" target="_blank"><img src="{$vo}" style="width: 60px; height: 60px;margin-bottom: 5px;"></a>
                        {/volist}
                    </div>
                </div>
                {/eyou:notempty}
            </div>

            <div class="block-wrap log">
                <div class="title color-base-text">维权日志</div>
                {volist name="$Log" id="vo"}
                <div class="item">
                    <div class="action">
                        <div class="title">
                            <span class="tit">{$vo.log_note}</span>
                            <span class="after-time">{$vo.add_time}</span>
                        </div>
                    </div>
                </div>
                {/volist}
            </div>

            <div class="placeholder-height"></div>
            <div class="footer-wrap">
                <div class="container">
                    {eq name="$Service.status" value="1"}
                    <button class="on" onclick="unifiedJump(this);" data-url="{:weapp_url('Mbackend/Shop/after_service_refund', ['service_id' => $Service.service_id])}">主动退款</button>
                    <!-- <button class="on" onclick="serviceManualRefund();">手动退款</button> -->
                    <button class="on" onclick="serviceAuditOpinion(2);">通过审核</button>
                    <button class="on" onclick="serviceAuditOpinion(3);">驳回申请</button>
                    {/eq}

                    {if condition="$Service.service_type == 1 && in_array($Service.status, [2, 4, 5])"}
                    {eq name="$Service.status" value="4"}
                    <button class="on" onclick="serviceAuditOpinion(5);">确认收货</button>
                    {/eq}
                    {eq name="$Service.status" value="5"}
                    <button class="on" onclick="unifiedJump(this);" data-url="{:weapp_url('Mbackend/Shop/after_service_resend', ['service_id' => $Service.service_id])}">确认发货</button>
                    <!-- <button class="on" onclick="serviceConfirmSend();">确认发货</button> -->
                    {/eq}
                    <button class="on" onclick="unifiedJump(this);" data-url="{:weapp_url('Mbackend/Shop/after_service_refund', ['service_id' => $Service.service_id])}">主动退款</button>
                    <!-- <button class="on" onclick="serviceManualRefund();">手动退款</button> -->
                    <button class="on" onclick="serviceConfirmComplete({$Service.status});">完成换货</button>
                    {/if}

                    {if condition="($Service.status == 2 && $Service.service_type == 3) || ($Service.status == 5 && $Service.service_type == 2)"}
                    <button class="on" onclick="unifiedJump(this);" data-url="{:weapp_url('Mbackend/Shop/after_service_refund', ['service_id' => $Service.service_id])}">转账</button>
                    {/if}

                    {if condition="$Service.service_type == 2 && in_array($Service.status, [2, 4, 5])"}
                    {eq name="$Service.status" value="4"}
                    <button class="on" onclick="serviceAuditOpinion(5);">确认收货</button>
                    {/eq}
                    <button class="on" onclick="unifiedJump(this);" data-url="{:weapp_url('Mbackend/Shop/after_service_refund', ['service_id' => $Service.service_id])}">主动退款</button>
                    <!-- <button class="on" onclick="serviceManualRefund();">手动退款</button> -->
                    <!-- <button class="on" onclick="serviceRefundBalance({$Service.status});">退款到余额</button> -->
                    {/if}

                    {eq name="$Service.manual_refund" value="1"}
                    <button class="on" onclick="layerAlert('{$Service.refund_note}', '关闭');">手动退款原因</button>
                    {/eq}
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        // 预定义变量
        var orderID = {$Service.order_id|default=0};
        var usersID = {$Service.users_id|default=0};
        var serviceID = {$Service.service_id|default=0};
        var detailsID = {$Service.details_id|default=0};
        var productID = {$Service.product_id|default=0};
        var serviceType = {$Service.service_type|default=0};
        var postData = {
            _ajax: 1,
            weappAjax: 1,
            users_id: usersID,
            order_id: orderID,
            details_id: detailsID,
            service_id: serviceID,
            product_id: productID,
            service_type: serviceType,
            status: 0,
            delivery: {},
            refund_note: '',
            refund_way: 0,
            actual_price: 0,
            actual_points: 0,
            manual_refund: 0,
        };

        // 手动退款
        function serviceManualRefund() {
            var content = '<div>是否确认手动完成服务单并自行退款？</div>';
            content += '<div id="manualRefundDiv"> <textarea id="refundNote" placeholder="请填写手动关闭订单原因(非必填)" style="width: 100%; height: 60px;"></textarea> </div>';
            layer.open({
                anim: 'up',
                content: content,
                btn: ['完成并退款', '取消'],
                title: ['手动退款'],
                success: function(layero, index) {
                    $('#manualRefundDiv #refundNote').focus();
                },
                yes: function(index) {
                    postData.manual_refund = 1;
                    postData.status = 1 === parseInt(serviceType) ? 6 : 7;
                    postData.refund_note = $('#manualRefundDiv #refundNote').val();
                    layer.close(index);
                    servicePerformOperation();
                }
            });
        }

        // 更新订单售后服务状态
        function serviceAuditOpinion(status) {
            // 重置更新状态值
            postData.status = status;
            // 判断提示文案
            var content = '';
            var showType = 1 == serviceType ? "<span style='color: blue;'>换货</span>" : "<span style='color: red;'>退货</span>";
            if (2 == status) {
                var btn = ['通过审核', '取消'];
                var content = '确认通过'+showType+'申请？';
            } else if (3 == status) {
                var btn = ['驳回申请', '取消'];
                var content = '确认驳回'+showType+'申请？';
            } else if (5 == status) {
                var btn = ['确定', '取消'];
                var content = '确认收到货物？';
            } else {
                layerMsg('类型错误，刷新重试', 1.5, function() {
                    window.location.reload();
                });
            }
            // 提示确认框
            layer.open({content: content, btn: btn,
                yes: function(index) {
                    servicePerformOperation();
                }
            });
        }

        // 退款到余额
        function serviceRefundBalance(value) {
            // 判断提示文案
            var content = '';
            if (2 == value) {
                content = "当前处于等待会员退货阶段，";
            } else if (4 == value) {
                content = "当前处于等待商家收货阶段，";
            } else if (5 == value) {
                content = "商家已收货，";
            }
            // 提示确认框
            layer.open({content: content + "确认完成售后服务并退款到余额？",
                btn: ['确定', '取消'],
                yes: function(index) {
                    postData.status = 7;
                    postData.refund_way = 1;
                    postData.actual_price = '{$Service.actual_price|default=0}';
                    postData.actual_points = '{$Service.actual_points|default=0}';
                    servicePerformOperation();
                }
            });
        }

        // 完成换货
        function serviceConfirmComplete(value) {
            // 判断提示文案
            var content = '';
            if (2 == value) {
                content = "当前处于等待会员发货阶段，";
            } else if (4 == value) {
                content = "当前处于等待商家收货阶段，";
            } else if (5 == value) {
                content = "当前处于等待商家发货阶段，";
            }
            // 提示确认框
            layer.open({content: content + "确认完成换货服务？",
                btn: ['完成换货', '取消'],
                yes: function(index) {
                    postData.status = 6;
                    servicePerformOperation();
                }
            });
        }

        // 确认重新发货
        function serviceConfirmSend() {
            var content = '<div id="confirmSend" style="margin-bottom: 20px;"> 快递公司：<input type="text" id="deliveryName" style="height: 25px;"> </div>';
            content += '<div id="confirmSend"> 快递单号：<input type="text" id="deliveryCode" style="height: 25px;"> </div>';
            layer.open({
                anim: 'up',
                content: content,
                btn: ['确定', '取消'],
                title: ['重新发货'],
                success: function(layero, index) {
                    $('#confirmSend #deliveryName').focus();
                },
                yes: function(index) {
                    postData.status = 6;
                    var deliveryName = $('#confirmSend #deliveryName').val();
                    var deliveryCode = $('#confirmSend #deliveryCode').val();
                    postData.delivery = {name: deliveryName, code: deliveryCode};
                    layer.close(index);
                    servicePerformOperation();
                }
            });
        }

        // 确认执行操作
        function servicePerformOperation() {
            // 提示处理
            layerLoading();
            // 提交处理
            $.ajax({
                url : "{:url('ShopService/after_service_handle')}",
                data: postData,
                type: 'post',
                dataType: 'json',
                success: function(res) {
                    layer.closeAll();
                    if (1 == res.code) {
                        layerMsg(res.msg, 1.5, function() {
                            window.location.reload();
                        });
                    } else {
                        layerMsg(res.msg, 1.5);
                    }
                }
            });
        }
    </script>
</body>
{include file="public/footer.htm" /}
